<template>
	<view class="wrap">
		<u-toast ref="uToast" />
		<view class="return_box zIndex">
			<view class="return_title">塔机黑匣子</view>
		</view>
		<view class="blank"></view>
		<view v-if="accessList&&accessList.length>0">
			<view class="access_box u-flex u-row-center u-col-center" v-for="(item,index) in accessList" :key="index"
				@tap="$u.throttle(fnGetDetails(item), APP.during)">
				<view class="access_tips u-flex u-row-center u-col-center u-p-b-10">
					<view class="dot" :class="APP.fnOnlineStatusText(item.heartbeatTime).status==0?'red':''"></view>
					<text>{{ APP.fnOnlineStatusText(item.heartbeatTime).text }}</text>
				</view>
				<view class="access_cont">
					<view class="cont_top u-flex u-row-between u-col-center u-p-b-10">
					</view>
					<view class="cont_center u-flex u-row-between u-col-center">
						<view class="item_left u-flex">
							<text>{{ '设备号:   '+item.number }}</text>
						</view>
					</view>
					<view class="cont_bottom u-flex u-row-between u-col-center">
						<view class="item_left" v-if="APP.fnAccessStatusToText(item.eqptStatus,'crane').status==0">
							{{ APP.fnAccessStatusToText(item.eqptStatus,'crane').msg }}
						</view>
						<view class="item_left orange"
							v-if="APP.fnAccessStatusToText(item.eqptStatus,'crane').status==1">
							{{ APP.fnAccessStatusToText(item.eqptStatus,'crane').msg }}
						</view>
						<view class="item_left red" v-if="APP.fnAccessStatusToText(item.eqptStatus,'crane').status==2">
							{{ APP.fnAccessStatusToText(item.eqptStatus,'crane').msg }}
						</view>
						<view class="item_right u-flex u-col-center">
							<image src="/static/svg/access_create.svg"></image>
							<text>{{ item.heartbeatTime?APP.fnGetDateFormat(item.heartbeatTime):'' }}</text>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore class="u-m-b-40 u-m-t-40" status="nomore" bgColor="#ffffff"></u-loadmore>
		</view>
		<u-empty style="width: 100%;height: 800rpx;" v-else text="没有更多数据" mode="list"></u-empty>
		<view class="page_bottom"></view>
		<!-- 更多 弹窗 -->
		<u-popup v-model="isMore" style="margin-top: 90rpx;" :closeable="true" mode="top" height="750rpx"
			border-radius="24">
			<More @fnClose="isMore = false"></More>
		</u-popup>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				isMore: false, // 更多
				accessList: []
			}
		},
		mounted() {
			
			// 计算屏幕分辨率比例
			const query = uni.createSelectorQuery().in(this);
			query.select('.top_tips').boundingClientRect();
			query.exec(data => {
				let _height = data ? data[0].height * 2 : 0
				this.APP.ratio = _height != 0 ? _height / 100 : 1
			});
			
			this.fnGetCraneList()
		},
		// 下拉刷新
		onPullDownRefresh() {
			let that = this
			setTimeout(function() {
				uni.stopPullDownRefresh();
				that.fnGetCraneList()
			}, 100);
		},
		methods: {
			// 跳转设备详情
			fnGetDetails(item) {
				uni.navigateTo({
					url: '/pages/index/detail?item=' + encodeURIComponent(JSON.stringify(item)),
					animationType: 'pop-in',
					animationDuration: 200
				});
			},
			// 获取设备列表
			fnGetCraneList() {
				
				// 模拟数据，应后端获取
				
				this.accessList = [{
					"id": 1549,
					"number": "2000006607",
					"record_number": "",
					"mfrs": "",
					"heartbeatTime": 1720235381,
					"isCalibration": true,
					"eqptStatus": "20000000"
				}]
			},
		}
	}
</script>

<style scoped lang="scss">
	@import '@/common/css/base.scss';

	.access_box {
		width: 684rpx;
		height: 220rpx;
		border-radius: 24rpx;
		margin: 30rpx auto 0;
		box-shadow: 0 0 24rpx rgba(0, 0, 0, 0.16);
		position: relative;

		.access_tips {
			position: absolute;
			left: -5rpx;
			top: 20rpx;
			width: 120rpx;
			height: 50rpx;
			color: #FFFFFF;
			font-size: 24rpx;
			background: url(@/static/svg/task_blue.svg) no-repeat;
			background-size: 100% 100%;

			.dot {
				width: 14rpx;
				height: 14rpx;
				border-radius: 7rpx;
				margin-right: 10rpx;
				background-color: #14D2B8;

				&.red {
					background-color: #FA3534;
				}
			}
		}

		.access_cont {
			width: 640rpx;
			height: 180rpx;

			.cont_top {
				width: 540rpx;
				height: 60rpx;
				margin-left: 100rpx;

				.item_left {
					width: 270rpx;
					height: 60rpx;
					font-size: 24rpx;
					color: #6E6E6E;

					image {
						width: 18rpx;
						height: 15rpx;
						margin-right: 5rpx;
					}
				}

				.item_right {
					width: 270rpx;
					height: 60rpx;
					text-align: center;
					font-size: 24rpx;
					color: #6E6E6E;
					overflow: hidden;
				}
			}

			.cont_center {
				width: 640rpx;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 24rpx;
				color: #6E6E6E;

				.item_left {
					width: 440rpx;
					height: 60rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					font-size: 24rpx;
					color: #6E6E6E;

					text {
						font-size: 36rpx;
						color: #3A3A3A;
					}
				}

				.item_right {
					width: 200rpx;
					height: 60rpx;
					text-align: right;
					color: #3A3A3A;
				}
			}

			.cont_bottom {
				width: 640rpx;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 24rpx;
				color: #6E6E6E;

				.item_left {
					width: 350rpx;
					color: #3776F6;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;

					&.orange {
						color: #FF9900;
					}

					&.red {
						color: #FA3534;
					}
				}

				.item_right {
					width: 290rpx;

					image {
						width: 30rpx;
						height: 30rpx;
						margin-right: 10rpx;
					}
				}
			}
		}
	}

	.popup_title {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		font-size: 36rpx;
		text-align: center;
		padding: 0 20rpx;

		.close {
			width: 60rpx;
			height: 60rpx;

			image {
				width: 48rpx;
				height: 48rpx;
			}
		}
	}

	.popup_field {
		width: 100%;
		height: 120rpx;
		padding: 0 20rpx;
		margin-top: 10rpx;
		border-bottom: 1rpx solid #BBBBBB;

		.item {
			height: 120rpx;
			font-size: 26rpx;

			&:first-child {
				width: 120rpx;
			}

			&:last-child {
				width: 420rpx;
				margin-left: 20rpx;
			}
		}
	}

	.popup_fields {
		width: 100%;
		height: 120rpx;
		padding: 0 20rpx;
		margin-top: 10rpx;
	}

	.popup_bottom {
		width: 100%;
		height: 80rpx;
		padding: 0 100rpx;

		button {
			font-size: 32rpx;
		}
	}
</style>